(function () {
    const support = document.getElementsByClassName('target-zan')[0];
    // console.log(document.getElementsByClassName('zan')[0]);
    let zancount = 0;
    support.addEventListener('click', suppFn);
    //点赞
    function suppFn() {
        //判断是否点赞
        console.dir(support.style.backgroundColor);
        if (support.style.backgroundColor == 'rgb(255, 255, 255)') {
            console.log(00);
            support.style.backgroundColor = '#2495ff';
            support.innerHTML = `<span class="iconfont">&#xe61f; </span> 已赞`;
            support.style.color = '#fff';

            //点赞
            function suppFn() {
                axios.get('/api/supp', {
                    params: {
                        uid: 1,
                        aid: 9
                    }

                }).then(function (res) {
                    console.log(res);
                }).catch(function (error) {
                    console.log(error);
                });
            }
            suppFn();
            //取消点赞
        } else {
            support.style.backgroundColor = '#fff';
            support.innerHTML = `<span class="iconfont">&#xe61f; </span> 赞`;
            support.style.color = '#2495ff';

            function suppFn() {
                axios.get('/api/del', {
                    params: {
                        uid: 1,
                        aid: 9
                    }

                }).then(function (res) {
                    console.log(res);
                }).catch(function (error) {
                    console.log(error);
                });
            }
            suppFn();
        }
        zancount++;
    }


    //收藏
    const collect = document.getElementsByClassName('pointer-btn')[0];
    let colcount = 0;
    collect.addEventListener('click', collFn);
    function collFn() {
        console.log(collect.innerHTML);
        if (collect.innerHTML=='<span class="iconfont coll"></span>收藏') {
            collect.innerHTML = `<span class="iconfont" coll>&#xe61e;</span>已收藏`;
            // coll.style.color = 'rgb(251, 235, 30)';

            
            function collFn() {
                axios.get('/api/coll', {
                    params: {
                        uid: 2,
                        aid: 10
                    }

                }).then(function (res) {
                    console.log(res);
                }).catch(function (error) {
                    console.log(error);
                });
            }
            collFn();
            //取消收藏
        } else {
            collect.innerHTML = `<span class="iconfont coll"></span>收藏`;
            // coll.style.color = '#a0a4b0'
            function collFn() {
                axios.get('/api/cancel', {
                    params: {
                        uid: 2,
                        aid: 10
                    }

                }).then(function (res) {
                    console.log(res);
                }).catch(function (error) {
                    console.log(error);
                });
            }
            collFn();
        }
        colcount++;
    }

})();

(function () {
    const zan = document.getElementsByClassName('zan')[0];
    const support = document.getElementsByClassName('target-zan')[0];
    axios.get('/api/supp1', {
        params: {
            uid: 1,
            aid: 9
        }
    }).then(function (res) {
        if (res.data.length>0) {
            support.style.backgroundColor = '#2495ff';
            support.innerHTML = `<span class="iconfont">&#xe61f; </span> 已赞`;
            support.style.color = '#fff';
        }
        console.log(res);
    }).catch(function (error) {
        console.log(error);
    });
})();
 (function(){
    const collect = document.getElementsByClassName('pointer-btn')[0];
    const collects = document.getElementsByClassName('coll')[0];
    axios.get('/api/collect', {
        params: {
            uid: 2,
            aid: 10
        }
    }).then(function (res) {
        if (res.data.length>0) {
        collect.innerHTML = `<span class="iconfont" coll></span>已收藏`;
        }
        console.log(res);
    }).catch(function (error) {
        console.log(error);
    });
})();
